package com.lnlyj.media.data.load;

import static com.lnlyj.media.Constants.URI_MEDIA;

/**
 * Created by Wanglei on 2019/6/24.
 */

public class QueryFactory {

    private static final String[] PROJECTION_ALBUM = new String[]{"DISTINCT bucket_id", "bucket_display_name"};
    private static final String SELECTION_ALBUM = "(media_type = 1 or media_type = 3)";

    private static final String[] PROJECTION_MEDIA = new String[]{"_id", "_data", "_size", "date_modified", "latitude", "longitude", "width", "height", "media_type", "duration"};
    private static final String SELECTION_MEDIA = "bucket_id=?";

    public static QueryConfig getAlbumConfig() {
        QueryConfig config = new QueryConfig(QueryConfig.QUERY_TYPE_ALBUM);

        config.uri = URI_MEDIA;
        config.projection = PROJECTION_ALBUM;
        config.selection = SELECTION_ALBUM;

        return config;
    }

    public static QueryConfig getImageConfig(int album) {

        QueryConfig config = new QueryConfig(QueryConfig.QUERY_TYPE_IMAGE);

        config.uri = URI_MEDIA;
        config.projection = PROJECTION_MEDIA;

        if (album == -1) {
            config.selection = SELECTION_MEDIA + " and media_type=1";
            config.selectionArgs = new String[]{String.valueOf(album)};
        }

        return config;
    }


    public static QueryConfig getVideoConfig(int album) {
        QueryConfig config = new QueryConfig(QueryConfig.QUERY_TYPE_VIDEO);

        config.uri = URI_MEDIA;
        config.projection = PROJECTION_MEDIA;

        if (album == -1) {
            config.selection = SELECTION_MEDIA + " and media_type=2";
            config.selectionArgs = new String[]{String.valueOf(album)};
        }


        return config;
    }

    public static QueryConfig getMediaConfig(long album) {
        QueryConfig config = new QueryConfig(QueryConfig.QUERY_TYPE_ALL);

        config.uri = URI_MEDIA;
        config.projection = PROJECTION_MEDIA;

        if (album != -1) {
            config.selection = SELECTION_MEDIA + " and " + SELECTION_ALBUM;
            config.selectionArgs = new String[]{String.valueOf(album)};
        } else {
            config.selection = SELECTION_ALBUM;
        }
        return config;
    }
}
